# -*- coding: UTF-8 -*-

from selenium import webdriver
import time,os
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By


def logint():
    file_path = os.path.join('file:///', os.getcwd(), "selenium.html")
    driver=webdriver.Chrome()
    driver.get(file_path)
    driver.implicitly_wait(5)
    driver.maximize_window()
    driver.implicitly_wait(1)
    name=driver.find_element_by_css_selector("div#signup input[name='username']")
    name.send_keys('rabbit')
    pwd=driver.find_element_by_css_selector("div#signup input[name='password']")
    pwd.send_keys("love")
    select=driver.find_element_by_css_selector("div#signup select[name='city']")
    Select(select).select_by_value("sz")
    btn=driver.find_element_by_css_selector("div#signup input[type='submit']")
    btn.click()
    loctor=(By.CSS_SELECTOR,'div#signup p')
    WebDriverWait(driver,30).until(ec.text_to_be_present_in_element(loctor,'注册成功'))
    resul=driver.find_element_by_css_selector("div#signup p")
    if resul.text=="注册成功":
        print("登录成功")
    else:
        print("登录失败")
    driver.quit()

logint()